package cn.kent.controller;

import lombok.Data;

import java.util.Date;

@Data
public class ResponseVo<T> {


    private T data;
    private String code;
    private String message;
    private boolean success;
    private Long timestamp;


    public static ResponseVo success(String method, ResponseData data) {
        ResponseVo responseVo = new ResponseVo();
//        responseVo.method = method;
//        responseVo.id = "1";
        return responseVo;
    }


    public ResponseVo success(T t) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setSuccess(true);
        responseVo.setCode("200");
        responseVo.setMessage("ok");
//        responseVo.method = method;
//        responseVo.id = "1";
        responseVo.setData(t);
        responseVo.setTimestamp(System.currentTimeMillis());
        return responseVo;
    }

    public static ResponseVo fail(String method, ResponseData data) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setSuccess(false);
        responseVo.setTimestamp(System.currentTimeMillis());
//        responseVo.method = method;
//        responseVo.id = "1";
        return responseVo;

    }

    public static ResponseVo fail(String msg) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setSuccess(false);
        responseVo.setCode("-1");
        responseVo.setData(msg);
        responseVo.setTimestamp(System.currentTimeMillis());
//        responseVo.id = "1";
        return responseVo;

    }
    public static ResponseVo fail(String code,String msg) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setSuccess(false);
        responseVo.setCode(code);
        responseVo.setData(msg);
        responseVo.setTimestamp(System.currentTimeMillis());
//        responseVo.id = "1";
        return responseVo;

    }


}

@Data
class ResponseData {

    String data1;
    String data2;

}

@Data
class ResponseError {
    String code;
    String message;
}